package top.kaoshanji.p1ch03a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.u1constant.FileConstant;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 代码清单 p1ch03a-10：使用输入流复制数据的示例
 * 运行之后会生成 深入理解Java7：核心技术与最佳实践-成富-随书源码-dest.7z 文件，看过之后就删掉
 * author kaoshanji
 * ^_^
 * create time 2025/1/6 19:47
 */
public class InputStreamExample03 {

    private static final Logger logger = LogManager.getLogger(InputStreamExample03.class);

    public static void main(String[] args) {
        logger.info("...代码清单 p1ch03a-10：使用输入流复制数据的示例...");

        byte[] buffer = new byte[32 * 1024];
        int len = -1;

        try (FileInputStream input = new FileInputStream(FileConstant.SRC_COPY_FILE);
             FileOutputStream output = new FileOutputStream(FileConstant.DEST_COPY_FILE)) {

            while ((len = input.read(buffer)) != -1) {
                output.write(buffer, 0, len);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }

}
